home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Beginner need help??????????????
- Date: Thu, 11 Apr 96 14:10:12 GMT
- Organization: none
- Distribution: world
- Message-ID: <829231812snz@genesis.demon.co.uk>
- References: <4kem82$5j3@dewey.csun.edu> <Pine.A32.3.91.960410160516.110349D-100000@black.weeg.uiowa.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <Pine.A32.3.91.960410160516.110349D-100000@black.weeg.uiowa.edu>
- robinson@blue.weeg.uiowa.edu "The Amorphous Mass" writes:
-
- >> ----------program 3---------------------------
- >> #include <stdio.h>
- >>
- >> int integer;
- >> float floating;
- >> main()
- >> {
- >> floating = 7.0 / 22.0;
- >> integer = floating;
- >> printf("The value of integer is %f\n", integer);
- >> return (0);
- >> }
- >>
- >> ???? The answer should be 0.31818 but compiler give me 0.000000 ?????
- >
- > In this case, floating gets 0.31818, but when you assign it to an int,
- >it truncates the fractional part. So integer == 0. Then you tell
- >printf() to print integer's value (0) as a float, and you get 0.000000.
-
- However it could have printed anything because trying to use %f to
- print an integer argument results in undefined behaviour.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-